package com.example.skycode5.servlet;

import com.example.skycode5.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/newsDel.jsp")
public class AdminDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int  NewsId = Integer.parseInt(req.getParameter("NewsId"));
        int result = (new NewsDao()).delete(NewsId);
        if (result >0) {
            resp.sendRedirect("news.jsp");
        }else {
            req.setAttribute("msg", "更新失败");//错误页面显示内容
            req.setAttribute("url" , "news.jsp");//显示错误信息后要跳转的页面
            req.getRequestDispatcher("WEB-INF/jsp/error.jsp").forward(req,resp);
        }
    }
}